package br.com.rafaelSys.entidades;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;

@Entity
@Name("ativoSerie")
@Table(name = "ATIVO_SERIE", uniqueConstraints=@UniqueConstraint(columnNames={"ativo_id","data"}))
@NamedQueries( { 
	@NamedQuery(name = "AtivoSerie.listByAtivo", query = "select s from AtivoSerie s where s.ativo = :ativo order by data"),
	@NamedQuery(name = "AtivoSerie.findUnique", query = "select s from AtivoSerie s where s.ativo = :ativo and s.data = :data")})
	public class AtivoSerie implements Serializable
	{

	private static final long serialVersionUID = -8444845401043121382L;

	private Integer id;
	private Ativo ativo;
	private Date data;
	private Double open;
	private Double high;
	private Double low;
	private Double close;
	private Long volume;

	private Double adj;

	public AtivoSerie() {

	}

	public AtivoSerie(Ativo ativo, Date data, Double open, Double high,
			Double low, Double close, Long volume, Double adj) {
		this.ativo = ativo;
		this.data = data;
		this.open = open;
		this.high = high;
		this.low = low;
		this.close = close;
		this.volume = volume;
		this.adj = adj;
	}

	public void atualizaValores(Double open, Double high,
			Double low, Double close, Long volume, Double adj) {
		this.open = open;
		this.high = high;
		this.low = low;
		this.close = close;
		this.volume = volume;
		this.adj = adj;
	}

	@Id
	@GeneratedValue
	public Integer getId()
	{
		return id;
	}
	public void setId(Integer id)
	{
		this.id = id;
	}

	@ManyToOne
	@NotNull
	public Ativo getAtivo() {
		return ativo;
	}

	public void setAtivo(Ativo ativo) {
		this.ativo = ativo;
	}

	@Column(name="open")
	public Double getOpen() {
		return open;
	}

	public void setOpen(Double open) {
		this.open = open;
	}

	@Column(name="high")
	public Double getHigh() {
		return high;
	}

	public void setHigh(Double high) {
		this.high = high;
	}

	@Column(name="low")
	public Double getLow() {
		return low;
	}

	public void setLow(Double low) {
		this.low = low;
	}

	@Column(name="close")
	public Double getClose() {
		return close;
	}

	public void setClose(Double close) {
		this.close = close;
	}

	@Column(name="volume")
	public Long getVolume() {
		return volume;
	}

	public void setVolume(Long volume) {
		this.volume = volume;
	}

	@Column(name="adj")
	public Double getAdj() {
		return adj;
	}

	public void setAdj(Double adj) {
		this.adj = adj;
	}

	@Column(name="data")
	@Temporal(TemporalType.DATE)
	public Date getData() {
		return data;
	}

	public void setData(Date data) {
		this.data = data;
	}


	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(ativo.getSimbolo());
		sb.append('\t');
		sb.append(data);
		sb.append('\t');
		sb.append(open);
		sb.append('\t');
		sb.append(high);
		sb.append('\t');
		sb.append(low);
		sb.append('\t');
		sb.append(close);
		sb.append('\t');
		sb.append(volume);
		return sb.toString();
	}
	}

